package com.example.onlineeducation.viewmodel

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.example.onlineeducation.base.BaseViewModel
import com.example.onlineeducation.repository.OfflineRepository
import com.yc.jetpacklib.net.YcResult
import kotlinx.coroutines.flow.collectLatest
import okhttp3.MultipartBody

class OfflineExamDetailVM : BaseViewModel() {

    private val mOfflineRepository: OfflineRepository by lazy { OfflineRepository(mApiService) }

    private val _mSubmitExamDetailsResult = MutableLiveData<YcResult<Any?>>()
    val mSubmitExamDetailsResult: LiveData<YcResult<Any?>> = _mSubmitExamDetailsResult

    fun submitExamDetails(id: String, costTime: String, point: String, testDate: String, mediaUrl: String? = null) = ycLaunch {
        mOfflineRepository.submitOfflineExamDetail(id, costTime, mediaUrl, point, testDate).ycHasLoading().collectLatest {
            _mSubmitExamDetailsResult.postValue(it)
        }
    }

//    private val _mOfflineExamDetails = MutableLiveData<YcResult<OfflineExamDetailEntity?>>()
//    val mOfflineExamDetails: LiveData<YcResult<OfflineExamDetailEntity?>> = _mOfflineExamDetails
//
//    fun getOfflineExamDetail(proId: String, examId: String, id: String) = ycLaunch {
//        mOfflineRepository.getOfflineExamRecordDetail(proId, examId, id).ycHasLoading().collectLatest {
//            _mOfflineExamDetails.postValue(it)
//        }
//    }


    /*
    * 提交考试详情（多图片）
    * */
    private val _mUploadMultipleFileResult = MutableLiveData<YcResult<List<String>?>>()
    val mUploadMultipleFileResult: LiveData<YcResult<List<String>?>> = _mUploadMultipleFileResult
    fun uploadMultipleFile(partLis: List<MultipartBody.Part>) = ycLaunch {
        mOfflineRepository.uploadMultipleFile(partLis).ycHasLoading().collectLatest {
            _mUploadMultipleFileResult.postValue(it)
        }
    }
}

